//
// Created by 19281121-赵路路@BJTU on 2021/9/17.
//
#pragma once

#include <iostream>
#include <string>

#define CaesarNum 3
using namespace std;

string Encryption(string str);

string Decryption(string str);

void Caesar() {
    // Preparations
    string plainText;
    string cipherText;
    string decryptedText;

    // Inputs
    cout << "Please enter the string you want to encrypt:" << endl;
    cin >> plainText;

    // Encrypt
    cipherText = Encryption(plainText);
    cout << "The ciphertext is: " << cipherText << endl;

    //Decrypt
    decryptedText = Decryption(cipherText);
    cout << "The decryptedtext is: " << decryptedText << endl;
}

string Encryption(string str) {
    for (char &i : str) {
        i = (i - 'a' + CaesarNum) % 26 + 'a';
    }
    return str;
}

string Decryption(string str) {
    for (char &i : str) {
        i = i - 'a';
        if (i < CaesarNum) {
            i += 26;
            i = (i - CaesarNum) % 26 + 'a';
            continue;
        }
        i = (i - CaesarNum) % 26 + 'a';
    }
    return str;
}